package tools;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 
 * @author sonseo
 *         http://javatechniques.com/blog/dateformat-and-simpledateformat-
 *         examples/
 */
public class DateTools {

	public String convertDateTxt2Txt(String txtDate, String oldDateFormat, String newDateFormat) {
		Date tempDate = convertTxt2Date(txtDate, oldDateFormat);
		return convertDate2Txt(tempDate, newDateFormat);
	}

	/**
	 * @param txtDate
	 * @param dateFormat "dd-MM-yyyy"
	 * @return Date
	 */
	public Date convertTxt2Date(String txtDate, String dateFormat) {
		Date result = new Date();

		SimpleDateFormat format = new SimpleDateFormat(dateFormat);
		try {
			result = format.parse(txtDate);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return result;
	}

	/**
	 * 
	 * @param date
	 * @param dateFormat
	 * @return String
	 */
	public static String convertDate2Txt(Date date, String dateFormat) {
		String result = "";
		SimpleDateFormat format = new SimpleDateFormat(dateFormat);
		result = format.format(date);
		return result;
	}

	public String GetCurrentTimeStamp() {
		java.util.Date date = new java.util.Date();
		Timestamp ts = new Timestamp(date.getTime());
		Integer intTS = ts.hashCode();
		return (intTS.toString());
	}

	public String getDateTime() {
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
		Date date = new Date();
		return dateFormat.format(date);
	}

	/**
	 * System.out.println("Now : " + SseoTools.now());
	 * 
	 * @return
	 */
	public static String now() {
		String DATE_FORMAT_NOW = "{yyyy-MM-dd HH.mm.ss}";
		//String DATE_FORMAT_NOW = "{HH.mm.ss}";
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
		return sdf.format(cal.getTime());
	}

}
